package com.share.example.selenium.web;

import com.share.common.common.Result;
import com.share.example.selenium.service.alibaba.buy.AlibabaClickGridBoxService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/alibaba")
public class AlibabaBuyController {
    @Autowired
    private AlibabaClickGridBoxService alibabaClickGridBoxService;

    //批量操作
    @RequestMapping("batch/click/grid")
    public Result batchClickGrid(Integer clickNum, String keyWord, String companyName) {
        if (clickNum == null || clickNum < 0 || clickNum > 10000) {
            clickNum = 1;
        }

        if (StringUtils.isEmpty(keyWord)) {
            keyWord = "Led desk lamp";
        }

        if (StringUtils.isEmpty(companyName)) {
            companyName = "Shenzhen Founder Industrial Co., Ltd";
        }

        Map<String, Object> reMap = alibabaClickGridBoxService.batchClickGrid(clickNum, keyWord, companyName);

        return Result.success(reMap);
    }

    //单纯操作
    @RequestMapping("/one/click/grid")
    public Result clickGrid(String keyWord, String companyName) {
        if (StringUtils.isEmpty(keyWord)) {
            keyWord = "Led desk lamp";
        }

        if (StringUtils.isEmpty(companyName)) {
            companyName = "Shenzhen Founder Industrial Co., Ltd";
        }

        Long aLong = alibabaClickGridBoxService.clickGrid(keyWord, companyName);

        return Result.success(aLong);
    }
}
